<?php

Yii::app()->getClientScript()->registerCoreScript( 'jquery.ui' );
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('menu-model-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php
$str_js = "
        var fixHelper = function(e, ui) {
            ui.children().each(function() {
                $(this).width($(this).width());
            });
            return ui;
        };
 
        $('#menu-model-grid table.items tbody').sortable({
            forcePlaceholderSize: true,
            forceHelperSize: true,
            items: 'tr',
            update : function () {
                serial = $('#menu-model-grid table.items tbody').sortable('serialize', {key: 'items[]', attribute: 'class'});
                $.ajax({
                    'url': '" . $this->createUrl('//admin/sort') . "',
                    'type': 'post',
                    'data': serial,
                    'success': function(data){
                    },
                    'error': function(request, status, error){
                        alert('We are unable to set the sort order at this time.  Please try again in a few minutes.');
                    }
                });
            },
            helper: fixHelper
        }).disableSelection();
    ";
 
    Yii::app()->clientScript->registerScript('sortable-project', $str_js);
    ?>

<h1>Manage Menu</h1>
<?php if(isset($_GET['group']))$group=$_GET['group'];else $group='mainmenu'?>
<?php echo CHtml::dropDownList('menu_page', $group,Common::getOptionValue('menugroup'),array('onchange'=>'window.location="/admin/report/?model=menu&group="+this.value')); ?>

<?php

$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'menu-model-grid',
    'dataProvider' => $model->search($group),
   // 'filter' => $model,
    'rowCssClassExpression'=>'"items[]_{$data->id}"',
    // 'enablePagination' => false,
    'columns' => array(
       // 'id',
        'label',
        //'description',
       'menu_url',
       'menu_group',
       //'parent_id',
//         array(
//                'name'=>'parent_id',   
//                'value'=>'MenuModel::model()->getLabel($data->parent_id)',
//        ),
        array(
                'name'=>'is_login',   
                'value'=>'Common::getOptionValue(\'usermenuaccess\',$data->is_login)',
        ),
       array(
            'class' => 'CButtonColumn',
            //'template'=>'{sort_up}{sort_down}{view}{update}{delete}',
            'viewButtonUrl' => 'Yii::app()->createUrl("/admin/view", array("id" => $data["id"],"model" => "menu"))',
            'deleteButtonUrl' => 'Yii::app()->createUrl("/admin/delete", array("id" =>  $data["id"],"model" => "menu"))',
            'updateButtonUrl' => 'Yii::app()->createUrl("/admin/update", array("id" =>  $data["id"],"model" => "menu"))',
        
        ),
    ),
));
?>
